# Maintainer: David Runge <dvzrv@archlinux.org>

_name=pyproject_api
pkgname=python-pyproject-api
pkgver=1.5.1
pkgrel=2
pkgdesc="API to interact with the python pyproject.toml based projects"
arch=(any)
url="https://github.com/tox-dev/pyproject-api"
license=(MIT)
depends=(
  python
  python-packaging
)
makedepends=(
  python-build
  python-hatch-vcs
  python-hatchling
  python-installer
  python-wheel
)
checkdepends=(
  python-pytest
  python-pytest-mock
  python-virtualenv
)
source=(https://files.pythonhosted.org/packages/source/${_name::1}/$_name/$_name-$pkgver.tar.gz)
sha512sums=('31936d242861027ea892e86219f430371aae18631c92893cefc8fb8fc02315906857ee57e5412eed62bf584e0bd24cca7ba82471c0ac6a72c71e8e93b8285a3e')
b2sums=('53ee778b4e04cac2f16ecd054adc7fd86373d6402f80d485fe22457252684f774b6a5df23d08cf6c6b1f96964d6dc1b1cc9014415f3d9105ffbb09421f69a11e')

build() {
  cd $_name-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  local pytest_options=(
    -vv
    # unclear why that fails
    --deselect tests/test_frontend.py::test_missing_backend
    # wants python2
    --deselect tests/test_frontend.py::test_can_build_on_python_2
  )
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  # install to temporary location, as importlib is used
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="$PWD/test_dir/$site_packages:$PYTHONPATH"
  pytest "${pytest_options[@]}"
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}
